//
//  NSAttributedString+Extension.swift
//  Weibo24
//
//  Created by apple on 17/4/8.
//  Copyright © 2017年 itheima. All rights reserved.
//

import UIKit

extension NSAttributedString {
    
    //  根据表情模型创建表情富文本
    class func attributedStringWithEmoticon(emoticon: HMEmoticon, font: UIFont) -> NSAttributedString {
    
        //  1. 创建图片对象
        let image = UIImage(named: emoticon.path!)
        //  2. 创建文本附件设置图片
        let attachMent = HMTextAttachment()
        //  设置图片
        attachMent.image = image
        //  设置表情模型
        attachMent.emoticon = emoticon
        
        //  获取字体的高度
        let lineHeight = font.lineHeight
        //  设置图片大小
        //  设置bounds改变子控件显示位置
        attachMent.bounds = CGRect(x: 0, y: -4, width: lineHeight, height: lineHeight)
        //  3. 根据文本附件创建富文本
        let attrbutedStr = NSAttributedString(attachment: attachMent)
        
        return attrbutedStr
        
    }
    
    
}
